#include "Utils.hh"
#include "BankSystem.hh"
#include "Account.hh"

using namespace BankSystem;

// 转账操作
void performTransfer(BankSystem::BankSystem& bankSystem, const std::shared_ptr<Account>& sourceAccount) {
    system("clear");
    SetConsoleOutputCP(CP_UTF8);
    std::cout << "===== Transfer from Account: " << sourceAccount->getAccountId() << " =====" << std::endl;
    std::cout << "Current Balance: " << Utils::formatCurrency(sourceAccount->getBalance()) << "\n" << std::endl;
    
    std::string destAccountId;
    std::cout << "Enter destination account ID: ";
    std::getline(std::cin, destAccountId);
    
    auto destAccount = bankSystem.getAccountById(destAccountId);
    if (!destAccount) {
        std::cout << "Error: Destination account not found." << std::endl;
        waitForEnter();
        return;
    }
    
    double amount;
    std::cout << "Enter amount to transfer: ";
    std::cin >> amount;
    clearInputBuffer();
    
    std::string note;
    std::cout << "Add note (optional): ";
    std::getline(std::cin, note);
    
    if (sourceAccount->transfer(destAccount, amount, note)) {
        std::cout << "\nTransfer successful!" << std::endl;
        std::cout << "New balance: " << Utils::formatCurrency(sourceAccount->getBalance()) << std::endl;
        std::cout << "Transaction ID: " << sourceAccount->getTransactions().back()->getTransactionId() << " has been recorded." << std::endl;
    }
    
    waitForEnter();
}
